package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.bo.VipGoodsBO;
import com.junzhiit.nengji.dao.VipGoodsDAO;
import com.junzhiit.nengji.model.VipGoods;
import com.junzhiit.nengji.model.enums.GoodsStatus;

@Repository
public class VipGoodsDAOImpl extends AbstractBaseDAO<VipGoods> implements VipGoodsDAO{

	@Override
	public List<VipGoodsBO> findByVipId(VipGoodsBO vipGoodsBO, int pageNumber, int maxPageRow) {
		StringBuffer sql = new StringBuffer();
		sql.append("select g.name 'goods_name',g.profit,g.is_open_sell,g.is_open_rebate,vg.status,g.type");
		sql.append(" from vip_goods vg ");
		sql.append(" inner join goods g on g.id=vg.goods_id");
		sql.append(" where vg.is_delete = ? and vg.vip_id = ?");
		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(vipGoodsBO.getVipId());
		return super.queryForPagingList(sql.toString(), VipGoodsBO.class, param, pageNumber, maxPageRow);
	}

	@Override
	public int getTotalCount(VipGoodsBO vipGoodsBO) {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(vg.*)");
		sql.append(" from vip_goods vg ");
		sql.append(" inner join goods g on g.id=vg.goods_id");
		sql.append(" where vg.is_delete = ? and vg.vip_id = ?");
		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(vipGoodsBO.getVipId());
		return super.queryForInt(sql.toString(), param);
	}

	@Override
	public List<VipGoodsBO> findByShopId(VipGoodsBO vipGoodsBO, int pageNumber, int maxPageRow) {
		StringBuffer sql = new StringBuffer();
		sql.append("select name 'goods_name',profit,is_open_sell,is_open_rebate,status,g.type");
		sql.append(" from goods where is_delete = ? and status = ? and shop_id = ?");
		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setInt(GoodsStatus.ACTIVE.toIntStatus());
		param.setString(vipGoodsBO.getShopId());
		return super.queryForPagingList(sql.toString(), VipGoodsBO.class, param, pageNumber, maxPageRow);
	}

	@Override
	public int getCount(VipGoodsBO vipGoodsBO) {
		StringBuffer sql = new StringBuffer();
		sql.append("select name 'goods_name',profit,is_open_sell,is_open_rebate,status,g.type");
		sql.append(" from goods where is_delete = ? and status = ?and shop_id = ?");
		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setInt(GoodsStatus.ACTIVE.toIntStatus());
		param.setString(vipGoodsBO.getShopId());
		return super.queryForInt(sql.toString(),param);
	}

}
